package com.smh.a02exerciseDemo1;

import java.io.*;

public class Test1 {
    public static void main(String[] args) throws IOException {
        //字节基本流
        FileInputStream fis = new FileInputStream("day27-code\\file\\a.txt");

        FileOutputStream fos = new FileOutputStream("day27-code\\file\\b.txt");
        int b;

        long start = System.currentTimeMillis();
        while ((b = fis.read()) != -1) {
            fos.write((char) b);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        fos.close();
        fis.close();

        //字节基本流(数组)
        FileInputStream fis1 = new FileInputStream("day27-code\\file\\a.txt");

        FileOutputStream fos1 = new FileOutputStream("day27-code\\file\\b.txt");

        byte[] bytes = new byte[1024 * 1024];
        int len;

        start = System.currentTimeMillis();
        while ((len = fis1.read(bytes)) != -1) {
            fos1.write(bytes, 0, len);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        fos1.close();
        fis1.close();

        //字节缓冲流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day27-code\\file\\a.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("day27-code\\file\\b.txt"));
        start = System.currentTimeMillis();
        while ((b = bis.read()) != -1) {
            bos.write((char) b);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        bos.close();
        bis.close();

        //字节缓冲流数组
        BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream("day27-code\\file\\a.txt"));
        BufferedOutputStream bos1 = new BufferedOutputStream(new FileOutputStream("day27-code\\file\\b.txt"));

        start = System.currentTimeMillis();
        while ((len = bis1.read(bytes)) != -1) {
            bos1.write(bytes, 0, len);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        bos1.close();
        bis1.close();


    }
}
